return XendNode.instance().pifs[ref]
def PIF_create(self, _, name, network_uuid, host_uuid, mac, mtu, vlan):
- node = XendNode.instance()
- if host_uuid != node.uuid:
- return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
-
- elif _is_valid_ref(network_uuid, node.is_valid_network):
- network = node.get_network(network_uuid)
- return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
- network))
- else:
- return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
+ try:
+ node = XendNode.instance()
+ if host_uuid != node.uuid:
+ return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
+
+ elif _is_valid_ref(network_uuid, node.is_valid_network):
+ network = node.get_network(network_uuid)
+ return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
+ network))
+ else:
+ return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
+ except NetworkAlreadyConnected, exn:
+ return xen_api_error(['NETWORK_ALREADY_CONNECTED',
+ network_uuid, exn.pif_uuid])
def PIF_destroy(self, _, ref):
return xen_api_success(XendNode.instance().PIF_destroy(ref))
return xen_api_success(self._get_PIF(ref).set_mtu(name))
def PIF_create_VLAN(self, _, ref, network, vlan):
- if _is_valid_ref(network, XendNode.instance().is_valid_network):
- return xen_api_success(XendNode.instance().PIF_create_VLAN(
- ref, network, vlan))
- else:
- return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
+ try:
+ if _is_valid_ref(network, XendNode.instance().is_valid_network):
+ return xen_api_success(XendNode.instance().PIF_create_VLAN(
+ ref, network, vlan))
+ else:
+ return xen_api_error([NETWORK_HANDLE_INVALID, network])
+ except NetworkAlreadyConnected, exn:
+ return xen_api_error(['NETWORK_ALREADY_CONNECTED',
+ network, exn.pif_uuid])
# Xen API: Class VM
config['device'] = ''
if not config.has_key('network'):
- config['network'] = \
- XendNode.instance().bridge_to_network(
- config.get('bridge')).uuid
+ try:
+ config['network'] = \
+ XendNode.instance().bridge_to_network(
+ config.get('bridge')).uuid
+ except Exception:
+ log.exception('bridge_to_network')
+ # Ignore this for now -- it may happen if the device
+ # has been specified using the legacy methods, but at
+ # some point we're going to have to figure out how to
+ # handle that properly.
config['MTU'] = 1500 # TODO
config['io_read_kbs'] = 0.0
return self.value
class VMBadState(XendError):
-
def __init__(self, value, expected, actual):
XendError.__init__(self, value)
self.expected = expected
self.actual = actual
- def __str__(self):
- return self.value
+class NetworkAlreadyConnected(XendError):
+ def __init__(self, pif_uuid):
+ XendError.__init__(self, 'Network already connected')
+ self.pif_uuid = pif_uuid
class VmError(XendError):
"""Vm construction error."""
from xen.util import Brctl
from xen.xend import uuid
-from xen.xend.XendError import XendError
+from xen.xend.XendError import XendError, NetworkAlreadyConnected
from xen.xend.XendRoot import instance as xendroot
from xen.xend.XendStorageRepository import XendStorageRepository
from xen.xend.XendLogging import log
for pif_uuid, pif in saved_pifs.items():
if pif['network'] in self.networks:
network = self.networks[pif['network']]
- self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
- pif['MAC'], network, False, pif_uuid)
+ try:
+ self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
+ pif['MAC'], network, False, pif_uuid)
+ except NetworkAlreadyConnected, exn:
+ log.error('Cannot load saved PIF %s, as network %s ' +
+ 'is already connected to PIF %s',
+ pif_uuid, pif['network'], exn.pif_uuid)
else:
for name, mtu, mac in linux_get_phy_ifaces():
network = self.networks.values()[0]
def PIF_create(self, name, mtu, vlan, mac, network, persist = True,
pif_uuid = None):
+ for pif in self.pifs.values():
+ if pif.network == network:
+ raise NetworkAlreadyConnected(pif.uuid)
+
if pif_uuid is None:
pif_uuid = uuid.createString()
self.pifs[pif_uuid] = XendPIF(pif_uuid, name, mtu, vlan, mac, network,
return self.networks[network_ref]
def bridge_to_network(self, bridge):
+ """
+ Determine which network a particular bridge is attached to.
+
+ @param bridge The name of the bridge. If empty, the default bridge
+ will be used instead (the first one in the list returned by brctl
+ show); this is the behaviour of the vif-bridge script.
+ @return The XendNetwork instance to which this bridge is attached.
+ @raise Exception if the interface is not connected to a network.
+ """
if not bridge:
rc, bridge = commands.getstatusoutput(
'brctl show | cut -d "\n" -f 2 | cut -f 1')
msgid ""
msgstr ""
"Project-Id-Version: Xen-xm 3.0\n"
-"PO-Revision-Date: 2006-12-25 19:24+0000\n"
+"PO-Revision-Date: 2006-12-28 15:43+0000\n"
"Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
"Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
"MIME-Version: 1.0\n"
msgid "VTPM_HANDLE_INVALID"
msgstr "The VTPM handle %(1)s is invalid."
+msgid "NETWORK_ALREADY_CONNECTED"
+msgstr "The network you specified already has a PIF attached to it, and so another one may not be attached."
+
msgid "VM_BAD_POWER_STATE"
msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."